/*******************************************************************************
 * Created on 04.04.2012
 *
 * Copyright(c) 1995 - 2011 T-Systems Multimedia Solutions GmbH
 * Riesaer Str. 5, 01129 Dresden
 * All rights reserved.
 *******************************************************************************/
package ua.rudolf.calculator.beans.dao;

import java.util.List;
import java.util.UUID;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import ua.rudolf.calculator.beans.impl.PersonImpl;

/**
 * // TODO Comment me!
 * 
 * @author arudenko
 */
@Repository("usersDao")
@Transactional
public class BeansDaoImpl implements BeansDao {

    private HibernateTemplate hibernateTemplate;

    @Autowired
    public void setSessionFactory(final SessionFactory sessionFactory) {
        hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    /**
     * @return the hibernateTemplate
     */
    public HibernateTemplate getHibernateTemplate() {
        return hibernateTemplate;
    }

    @Transactional(readOnly = false)
    public void saveUser(final PersonImpl user) {
        hibernateTemplate.saveOrUpdate(user);

    }

    @Transactional(readOnly = false)
    public void deleteUser(final PersonImpl user) {
        hibernateTemplate.delete(user);

    }

    @SuppressWarnings("unchecked")
    public List<PersonImpl> getAllUser(final PersonImpl user) {
        return hibernateTemplate.find("from " + PersonImpl.class.getName());
    }

    public PersonImpl selectUserById(final UUID userId) {
        return hibernateTemplate.get(PersonImpl.class, userId);
    }
}
